package vfs.server.config;

import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;

/**
 * User: serge
 * Date: 16.11.13
 * Time: 21:04
 */
public class ConfigHandler extends DefaultHandler
{
    private boolean listenPort;

    @Override
    public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException
    {
        if (qName.equals("listenPort"))
        {
            listenPort = true;
        }
    }

    @Override
    public void characters(char[] ch, int start, int length) throws SAXException
    {
        if (listenPort)
        {
            try
            {
                Config.listenPort = Integer.parseInt(new String(ch, start, length));
            }
            catch (NumberFormatException e)
            {
                e.printStackTrace();
            /* listenPort remains default */
            }

            listenPort = false;
        }
    }
}
